 <?php
class Contact extends CActiveRecord {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return "ts_contact";
    }
    
    
    
    public function attributeLabels() {
        return array(
            "member_id" => "รหัสผู้ใช้งาน",
            "contact_title" => "หัวข้อเรื่อง",
            "contact_description" => "รายละเอียด",
            "contact_approve" => "สถานะการตอบกลับ",
            "contact_status" => "สถานะ",
            "contact_create_date" => "วันที่",
            "contact_modified_date" => "วันที่แก้ไข",
        );
    }
    
//    public function rules() {
//        return array(
//            array("company_news_name, company_news_description", "required",'message'=>'กรุณากรอกข้อมูลให้ครบ'),
//            array("company_news_name", "length", "max" => 255),
//            array("company_news_description", "length", "max" => 255),
//        );
//    }
    
    public function search() {
        $criteria = new CDbCriteria;
        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }
    
    public function beforeValidate() {
        if ($this->isNewRecord) {
            $this->contact_status = 1;
            $this->contact_create_date = new CDbExpression("NOW()");
        }
        else
        {
            $this->contact_modified_date = new CDbExpression("NOW()");
        }

        return parent::beforeValidate();
    }
    
    public function relations() {
        return array(
            "member" => array(self::BELONGS_TO, "Member", "member_id")
        );
    }
    
}
?>
